﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data.DisplayOptions2
{

    /// <summary>
    /// 对应网格数据  它包含的选项卡：DOGrid3d（网格），DOModFlow（modflow项目），DOMt3d（mt3d项目）  
    /// </summary>
    [Serializable ]
    
   public class DOGrid3dData:EventProperty ,IObjectDataHelper ,   ICloneable 
    {

       public DOGrid3dData()
       {

           this._grid3d = new DOGrid3d();

           ////this._map = new DOMap();

           this._modflow = new DOModFlow();
           this._particles = new DOParticles();


       }
        

        
      


       DOGrid3d _grid3d;

       public DOGrid3d Grid3d
       {
           get { return _grid3d; }
           //set { _grid3d = value; }
       }


        DOModFlow _modflow;

        public DOModFlow Modflow
        {
            get { return _modflow; }
            set
            {
                _modflow = value;
            }

        }

        DOParticles _particles;

        public DOParticles Particles
        {
            get { return _particles; }
            set { _particles = value; }

        }

        public override void SetIsNeedUpdateDataToFalse()
        {
            base.SetIsNeedUpdateDataToFalse();

            this.isNeedUpdateData = false;

            if (this._grid3d !=null )
            {
                   this._grid3d.SetIsNeedUpdateDataToFalse();
            }
            if (this._modflow !=null )
            {
                this._modflow.SetIsNeedUpdateDataToFalse();
            }

            if (this._particles !=null )
            {
                 this._particles.SetIsNeedUpdateDataToFalse();
            }

           


        }


        public override void ProjAddDataVisibleChanged(bool isVisible)
        {
            base.ProjAddDataVisibleChanged(isVisible);


            //左侧 List 控件中的可见性
            this._isShowTab = isVisible;


            //网格选项卡的可见性
            if (this._grid3d != null)
            {

                this._grid3d.ProjAddDataVisibleChanged(true);
            }
            else 
            {
                this._grid3d = new DOGrid3d();
            }
  
        }
        /// <summary>
        /// 所有依赖于网格的数据（选项卡）不可见
        /// </summary>
        /// <param name="isVisible"></param>
        public override void ProjDeleteDataVisibleChanged(bool isVisible)
        {
            base.ProjDeleteDataVisibleChanged(isVisible);

            this._isShowTab = isVisible;

            if (this._grid3d !=null )
            {
                this._grid3d.ProjDeleteDataVisibleChanged(isVisible ); 
            }

            if (Modflow != null)
            {
                Modflow.ProjDeleteDataVisibleChanged(isVisible);
            }

            if (Particles != null)
            {
                Particles.ProjDeleteDataVisibleChanged(isVisible);
            }


        } 


       #region ICloneable 成员

        public object Clone()
       {

           DOGrid3dData obj=(DOGrid3dData )this.MemberwiseClone ();

           if (this._grid3d != null)
           {
               obj._grid3d = (DOGrid3d)this._grid3d.Clone();
           }
           else
           {
               obj._grid3d = null;
           }
           if (this._modflow!=null )
           {              
               obj._modflow = (DOModFlow)this._modflow.Clone();
           }
           else
           {
               obj._modflow = null ;
           }

           if (this._particles != null)
           {
               obj._particles = (DOParticles)this._particles.Clone();
           }
           else
           {
               obj._particles = null;
           }
          

           return obj;
       }

       #endregion

        #region IObjectDataHelper 成员

        /// <summary>
        /// 更新副本数据到原始数据数据   判断对应的选项改变，并作出对应的更新动作
        /// </summary>
        /// <param name="obj">副本数据</param>
        public void ResetDataAndTriggerEvent(object obj)
        {
        
            if (obj == null)
            {
                return;
            }

            DOGrid3dData doGrid3dData = (DOGrid3dData)obj;

            if (doGrid3dData .IsDataChanged () ==false )
            {
                return;
            }
    
            try
            {
                if (this._grid3d!=null)
                {
                    this._grid3d.ResetDataAndTriggerEvent(doGrid3dData._grid3d);
                }
                if ( this._modflow!=null)
                {
                    this._modflow.ResetDataAndTriggerEvent(doGrid3dData._modflow);
                }

                if ( this._particles!=null )
                {
                    this._particles.ResetDataAndTriggerEvent(doGrid3dData._particles);
                }

            }
            catch
            {

            }


            //throw new NotImplementedException();
        }

     
        public bool IsDataChanged( )
        {
            if (this==null )
            {
                return false;
            }

            if (this._isShowTab ==false )
            {
                return false;
            }
            if (this.IsNeedUpdateData == true)
            {
                return true;
            }
            else
            {
                if (( _grid3d !=null && _grid3d.IsDataChanged() == true )||( _modflow !=null && _modflow.IsDataChanged() == true )|| (_particles !=null &&  _particles.IsDataChanged() == true))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            
            }



            //return true;
            //throw new NotImplementedException();
        }

        #endregion


        #region 暂时不使用


        //// <summary>
        ////  判断对应的选项改变，并作出对应的更新动作
        //// </summary>
        //// <param name="doGrid3dData"></param>
        //public void ResetDOGrid3dData(DOGrid3dData doGrid3dData)
        //{

        //    try
        //    {
        //        this._grid3d.ResetDOGrid3d(doGrid3dData._grid3d);

        //        this._modflow.ResetDOModflow(doGrid3dData._modflow);

        //        this._particles.ResetDOParticles(doGrid3dData._particles);
        //    }
        //    catch
        //    {

        //    }
        //}


        //#region 事件模型
        //[field: NonSerialized]
        //public event EventHandler<DisplayOptionsChangedEventArgs> DisplayOptionsChanged;
        //public void AskDisplayOptionChanged(DisplayOptionsChangedEventArgs e)
        //{
        //    if (DisplayOptionsChanged != null)
        //    {
        //        DisplayOptionsChanged(this, e);
        //    }
        //}
        //#endregion


        #endregion



    }
}
